package com.graduation.springbootinit.utils;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import org.springframework.stereotype.Component;

@Component
public class IdGenerator implements IdentifierGenerator {
    
    private static long sequence = 0L;
    private static final long SEQUENCE_BITS = 12L;
    private static final long SEQUENCE_MASK = ~(-1L << SEQUENCE_BITS);
    
    @Override
    public Number nextId(Object entity) {
        long timestamp = System.currentTimeMillis();
        sequence = (sequence + 1) & SEQUENCE_MASK;
        return ((timestamp << SEQUENCE_BITS) | sequence);
    }
} 